package vip.meeet.thread;

public class InterruptStart {


    public static void main(String args[]){
//        mainInterrupted();
        isInterrupted();
    }

    private static void isInterrupted(){
        Thread thread = new MyThread();
        thread.start();
        thread.interrupt();
        System.out.println("stop 1??" + thread.isInterrupted());
        System.out.println("stop 2??" + thread.isInterrupted());
    }

    private static void mainInterrupted(){
        Thread.currentThread().interrupt();
        System.out.println("stop 1??" + Thread.interrupted());//true没有被中断
        System.out.println("stop 2??" + Thread.interrupted());//false，上一行调用执行了中断
        System.out.println("End");
    }

    private static void interrupted(){
        Thread thread = new MyThread();
        thread.start();
        try {
            Thread.sleep(2000);
            thread.interrupt();

            System.out.println("stop 1??" + thread.interrupted());
            System.out.println("stop 2??" + thread.interrupted());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    private static class MyThread extends Thread {
        public void run(){
            super.run();
            for(int i=0; i<500000; i++){
                i++;
//            System.out.println("i="+(i+1));
            }
        }
    }
}
